/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: cbus_service_private.h
 *
 * Purpose: implementation internal private API for cbus service
 *
 * Developer:
 *   wen.gu , 2022-02-16
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __CBUS_SERVICE_PRIVATE_H__
#define __CBUS_SERVICE_PRIVATE_H__

#include <stdio.h>

#include "cbus/core/cbus_type.h"
#include "cbus/core/cbus_error.h"
#include "cbus/core/cbus_map.h"
#include "cbus/bus/cbus_service.h"
#include "cbus/bus/cbus_endpoint.h"
#include "cbus/bus/cbus_event_publisher.h"
#include "cbus/bus/cbus_service_property.h"
#include "cbus/bus/cbus_message_manager.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/
#define CBUS_SERVICE_ENDPOINT_ARRAY_SIZE (8)
/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
G_C_HEADER_START


typedef cbus_message_on_process_func cbus_service_on_message_func;


typedef struct _endpoint_info
{
    cbus_endpoint_t endpoint;
    cbus_service_t service_ref;
}endpoint_info_t;

struct _cbus_service
{
    GU08 interface_version; /** the interface of current service */
    cbus_event_publisher_t event_publisher;
    cbus_srv_property_t properties;

    /** map<endpoint_addr, cbus_endpoint_info_t*> 
     * or list<cbus_endpoint_info_t*>
     */
    GU32 endpoint_array_count;
    endpoint_info_t endpoint_array[CBUS_SERVICE_ENDPOINT_ARRAY_SIZE];
};

/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/


GErrc cbus_service_message_register(cbus_service_t service, cbus_message_type_t message_type, cbus_message_id message_id, cbus_service_on_message_func on_message, GPTR opaque);
GErrc cbus_service_message_register_category(cbus_service_t service, cbus_message_type_t message_type, cbus_service_on_message_func on_message, GPTR opaque);
GErrc cbus_service_message_register_group(cbus_service_t service, const cbus_message_group_t* group);

GErrc cbus_service_message_unregister(cbus_service_t service, cbus_message_type_t message_type, cbus_message_id message_id);
GErrc cbus_service_message_unregister_category(cbus_service_t service, cbus_message_type_t message_type);
GErrc cbus_service_message_unregister_all(cbus_service_t service);




//GErrc cbus_service_message_send_response(cbus_service_t service, cbus_message_t request_message, GU08 return_code);
//GErrc cbus_service_message_send_response2(cbus_service_t service, const cbus_message_t* request_message, cbus_buffer_t response_data);

/**if this send is broad cast, the message->client_id is NULL, then check broadcast_ignore_error: GTRUE: ignore error, GFALSE: not ignore, just return if error occur */
//GErrc cbus_service_message_send(cbus_service_t service, cbus_message_t message, GBOL broadcast_ignore_error);


G_C_HEADER_END



#endif /** !__CBUS_SERVICE_PRIVATE_H__ */

